#include "option.h"

COption::COption(int nIndex, const string &szOptionText)
    : CUIText(szOptionText, "bomberman"),
      m_bActive(false),
      m_szOriginalText(szOptionText),
      m_fActiveRed(103.0f),
      m_fActiveGreen(86.0f),
      m_fActiveBlue(68.0f),
      m_fActiveAlpha(255.0f),
      m_nIndex(nIndex),
      m_fInactiveRed(225.0f),
      m_fInactiveGreen(211.0f),
      m_fInactiveBlue(195.0f),
      m_fInactiveAlpha(255.0f),
      m_pFunction(nullptr)

{
    setActive(false);
}

int COption::getIndex() const 
{
    return m_nIndex;
}

string COption::getOriginalText() const
{
    return m_szOriginalText;
}

void COption::setActive(bool active)
{
    if (active)
    {
        setColour(m_fActiveRed, m_fActiveGreen, m_fActiveBlue, m_fActiveAlpha);
        setText(string("- ") + m_szOriginalText);
    }
    else
    {
        setText(string("  ") + m_szOriginalText);
        setColour(m_fInactiveRed, m_fInactiveGreen, m_fInactiveBlue, 
            m_fInactiveAlpha);
    }
    m_bActive = active;
}

bool COption::getActive()
{
    return m_bActive;
}

void COption::setFunction(void (*function)(CMenu*, COption *, 
    DELAY_PARAMS &, unsigned char chKey))
{
    m_pFunction = function;
}

void COption::callFunction(CMenu *pMenu, unsigned char chKey)
{
    if (m_pFunction != nullptr)
    {
        (*m_pFunction)(pMenu, this, m_arrParams, chKey);
    }
}

void COption::registerParam(void *pData, utils::TYPE_VALUE nType, int nSize)
{
    utils::PARAM data = {pData, nType, nSize};
    m_arrParams.push_back(data);
}

void COption::setActiveColour(float red, float green, float blue, float alpha)
{
    m_fActiveRed = red;
    m_fActiveGreen = green;
    m_fActiveBlue = blue;
    m_fActiveAlpha = alpha;
    if (getActive())
    {
        setColour(m_fActiveRed, m_fActiveGreen, m_fActiveBlue, m_fActiveAlpha);
    }
}

void COption::setInactiveColour(float red, float green, float blue, float alpha)
{
    m_fInactiveRed = red;
    m_fInactiveGreen = green;
    m_fInactiveBlue = blue;
    m_fInactiveAlpha = alpha;
    if (! getActive())
    {
        setColour(red, green, blue, alpha);
    }
}

void COption::getActiveColour(float &red, float &green, float &blue, 
    float &alpha)
{
    red = m_fInactiveRed;
    green = m_fInactiveGreen;
    blue = m_fInactiveBlue;
    alpha = m_fInactiveAlpha;
}

void COption::getInactiveColour(float &red, float &green, float &blue, 
    float &alpha)
{
    red = m_fActiveRed;
    green = m_fActiveGreen;
    blue = m_fActiveBlue;
    alpha = m_fActiveAlpha;
}